package com.cqc.manage.repositories;

import com.cqc.manage.entity.CostStatistics;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface CostStatisticsRepositories extends JpaRepository<CostStatistics,String>, JpaSpecificationExecutor<CostStatistics> {


    @Query(nativeQuery = true ,value = "SELECT cost_statistics.constart_no from cost_statistics")
    List<String> findAllContractNo();

    @Query(nativeQuery = true ,value = "select contract_no from message_business where engineer = ?")
    List<String> getAllContractNo(String engineer);


    void deleteByEngeer(String engineerName);

//    @Query(nativeQuery = true , value = )
//    List<String> findAllAmountReceived();

    List<CostStatistics> findByEngeer(String name);

    /**
     * 查询
     * @param engName  工程师姓名
     * @param nature    业务类型
     * @return
     */
    List<CostStatistics> findByEngeerAndAndNature(String engName,String nature);

    CostStatistics findByConstartNo(String constartNo);

//    /**
//     * 查询每个公司的业务量，选取前20行
//     */
//
//    @Query("select DISTINCT client,sum(agreement_amount) from cost_statistics GROUP BY client ORDER BY sum(agreement_amount) DESC limit 20")
//    Map<String,Integer> selectCompanyAgreementAmount();

}
